﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Badger.Vhdl;

#endregion

namespace Weazel.Badger
{
  public class VhdlRegister
  {
    private RegisterEntity entity;

    /// <summary>
    /// The name of this register
    /// </summary>
    private readonly string name;
    public string Name
    {
      get 
      {
        return name;
      }
    }

    private GezelType gezelType;
    public GezelType GezelType
    {
      get
      {
        return gezelType;
      }

      set
      {
        gezelType = value;
      }
    }


    /// <summary>
    /// the type of this register
    /// </summary>
    private readonly Vhdl.Types.Type type;
    public Vhdl.Types.Type Type
    {
      get
      {
        return type;
      }
    }

    /// <summary>
    /// The read end of this register
    /// </summary>
    private readonly RegisterReadSignal readSignal;
    public RegisterReadSignal ReadSignal
    {
      get 
      {
        return readSignal;
      }
    }

    /// <summary>
    /// The read end of this register
    /// </summary>
    private readonly RegisterWriteSignal writeSignal;
    public RegisterWriteSignal WriteSignal
    {
      get
      {
        return writeSignal;
      }
    }

 
    public void Resolve(Entity entity, Process process, Vhdl.Statements.StatementCollection statements)
    {
      if (resolved)
        return;

      resolved = true;

      readSignal.GetPossibleTypes();
			readSignal.SetActualType(entity, process, statements, type);      
    }

    private bool r = false;
    private bool resolved
    {
      get
      {
        return r;
      }
      set
      {
        r = value;
      }
    }

   

    public VhdlRegister(RegisterEntity entity, Vhdl.Types.Type type, GezelType gezelType, string name)
    {
      this.name = name;
      this.type = type;  
      this.entity = entity;
      this.GezelType = gezelType;

      this.readSignal = new RegisterReadSignal(this);
      this.writeSignal = new RegisterWriteSignal(this);

      this.entity.AddSignal(readSignal);
      this.entity.AddSignal(writeSignal);

      this.entity.AddDeclarativeItem(readSignal);
      this.entity.AddDeclarativeItem(writeSignal);
    }
  }
}
